<template>
	<view>
		<view class="list grid col-3 align-center justify-center">
			<block v-for="(item, index) in dataList" :key="index">
				<view class="video">
					<image :src="item.imgurl" mode="aspectFill"></image>
		  <view class="like2 align-center">
			  <text class="tn-icon-relation tn-color-white" style="font-size: 35rpx;color: #5d5d5f;" @click="tn('/circlePages/reserve?zsid='+item.zsid)"></text>
		  		<!-- <text class="tn-icon-delete-fill tn-padding-right-xs tn-text-lg" @click="delAi(item.zsid)" v-if="item.userid == userInfo.userid"></text> -->
		    <!-- <image src="/static/img/index/xin-2.png"></image> -->
		    <!-- <text>{{item.link}}</text> -->
		  </view>
          <view class="like align-center">
			  <text class="tn-icon-delete-fill tn-padding-right-xs tn-text-lg" @click="delAi(item.zsid)" v-if="item.userid == userInfo.userid"></text>
			  <text class="tn-icon-delete-fill tn-padding-right-xs tn-text-lg" @click="focus(item.zsid,0)" v-if="item.userid != userInfo.userid"></text>
            <!-- <image src="/static/img/index/xin-2.png"></image> -->
            <!-- <text>{{item.link}}</text> -->
          </view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		dataList: {}
	},
	data() {
		return {
			userInfo: uni.getStorageSync('userInfo') || null,
		};
	},
	methods: {
		focus(id,mytype){
			var that = this;
			if(mytype == 1){
				uni.showModal({
					title: '提示',
					content: '是否确定收藏智能体?',
					success: function(res) {
						if (res.confirm) {
							let formData = {
								zsid: id,
								userid: that.userInfo.userid,
								type: mytype
							};
							that.$Request.postApi("/module.php?m=aichat_zhushou_user&a=use&ajax=1", formData).then((res) => {
								if (res.error == 0) {
									uni.showToast({
									title: '收藏成功',
									icon: 'none',
									duration: 1000
									});
									that.getAllData();
								} else {
									uni.showModal({
										showCancel: false,
										title: '收藏失败',
										content: res.message,
									});
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}else{
				uni.showModal({
					title: '提示',
					content: '是否确定取消收藏智能体?',
					success: function(res) {
						if (res.confirm) {
							let formData = {
								zsid: id,
								userid: that.userInfo.userid,
								type: mytype
							};
							that.$Request.postApi("/module.php?m=aichat_zhushou_user&a=use&ajax=1", formData).then((res) => {
								if (res.error == 0) {
									uni.showToast({
									title: '取消收藏成功',
									icon: 'none',
									duration: 1000
									});
									that.getAllData();
								} else {
									uni.showModal({
										showCancel: false,
										title: '取消收藏失败',
										content: res.message,
									});
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		},
		delAi(id){
			var that = this;
			uni.showModal({
				title: '提示',
				content: '是否确定删除智能体（注意：删除后不可恢复）?',
				success: function(res) {
					if (res.confirm) {
						console.log('用户点击确定');
						let formData = {
							zsid: id,
							status: 11,
							userid: that.userInfo.userid
						};
						that.$Request.postApi("/module.php?m=aichat_zhushou&a=delete&ajax=1", formData).then((res) => {
							if (res.error == 0) {
								uni.showToast({
								title: '删除成功',
								icon: 'none',
								duration: 1500
								});
								that.getAllData();
							} else {
								uni.showModal({
									showCancel: false,
									title: '获取数据失败',
									content: res.message,
								});
							}
						});
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		// 跳转
		tn(e) {
		  uni.navigateTo({
		    url: e,
		  });
		}
	}
};
</script>

<style>
.list {
	display: flex;
	/* justify-content:space-between; */
	flex-wrap: wrap;
	padding-bottom: 100rpx;
	padding-left: 15rpx;
	background: #1c1d21;
	box-sizing: border-box;
  width: 100%;
}
.video{
  height: 360rpx;
  position: relative;
}
.grid.col-3>view {
	width: 244rpx;
  margin-bottom: 10rpx;
}
.video image{
  width: 100%;
  height: 100%;
}
.video .like{
  position: absolute;
  left: 80%;
  bottom: 10rpx;
  color: #FFF;
  display: flex;
}
.video .like image{
  width: 40rpx;
  height: 40rpx;
  margin-right: 6rpx;
}
.video .like2{
  position: absolute;
  left: 6%;
  bottom: 10rpx;
  color: #FFF;
  display: flex;
}
.video .like2 image{
  width: 40rpx;
  height: 40rpx;
  margin-right: 6rpx;
}
</style>
